package com.rickpan.dto.response;

import com.rickpan.entity.TeamMember;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;

/**
 * 团队成员响应DTO
 */
@Schema(description = "团队成员信息响应")
public class TeamMemberResponse {

    @Schema(description = "成员ID", example = "1")
    private Long id;

    @Schema(description = "团队ID", example = "1")
    private Long teamId;

    @Schema(description = "用户ID", example = "2")
    private Long userId;

    @Schema(description = "用户名", example = "john_doe")
    private String username;

    @Schema(description = "用户昵称", example = "John Doe")
    private String nickname;

    @Schema(description = "用户头像", example = "https://example.com/avatar.jpg")
    private String avatarUrl;

    @Schema(description = "成员角色", example = "MEMBER", allowableValues = {"OWNER", "ADMIN", "MEMBER"})
    private TeamMember.Role role;

    @Schema(description = "成员状态", example = "ACTIVE", allowableValues = {"ACTIVE", "INACTIVE", "REMOVED"})
    private TeamMember.Status status;

    @Schema(description = "加入时间", example = "2025-01-11T10:00:00")
    private LocalDateTime joinedAt;

    @Schema(description = "是否在线", example = "true")
    private Boolean isOnline;

    // 构造函数
    public TeamMemberResponse() {}

    public TeamMemberResponse(TeamMember teamMember) {
        this.id = teamMember.getId();
        this.teamId = teamMember.getTeamId();
        this.userId = teamMember.getUserId();
        this.role = teamMember.getRole();
        this.status = teamMember.getStatus();
        this.joinedAt = teamMember.getJoinedAt();
        this.isOnline = false; // 默认离线，需要从在线状态服务获取
    }

    // 静态工厂方法
    public static TeamMemberResponse from(TeamMember teamMember) {
        return new TeamMemberResponse(teamMember);
    }

    // Getter和Setter方法
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getTeamId() {
        return teamId;
    }

    public void setTeamId(Long teamId) {
        this.teamId = teamId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public TeamMember.Role getRole() {
        return role;
    }

    public void setRole(TeamMember.Role role) {
        this.role = role;
    }

    public TeamMember.Status getStatus() {
        return status;
    }

    public void setStatus(TeamMember.Status status) {
        this.status = status;
    }

    public LocalDateTime getJoinedAt() {
        return joinedAt;
    }

    public void setJoinedAt(LocalDateTime joinedAt) {
        this.joinedAt = joinedAt;
    }

    public Boolean getIsOnline() {
        return isOnline;
    }

    public void setIsOnline(Boolean isOnline) {
        this.isOnline = isOnline;
    }

    @Override
    public String toString() {
        return "TeamMemberResponse{" +
                "id=" + id +
                ", teamId=" + teamId +
                ", userId=" + userId +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", avatarUrl='" + avatarUrl + '\'' +
                ", role=" + role +
                ", status=" + status +
                ", joinedAt=" + joinedAt +
                ", isOnline=" + isOnline +
                '}';
    }
}
